import time

import requests


def get_page():
    url = 'http://www.1kkk.com/image3.ashx?t=1581742875000'
    # 伪造请求头
    headers = {
        "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"
    }
    respose = requests.get(url, headers=headers)
    if respose.status_code == 200:
        # respose.conent返回的是字节流，用decode转换成字符串
        return respose.content
    return None


# 保存图片
def save_image(data,name):
    filename = './images/%s.png'% str(name)
    with open(filename,'wb') as f:
        f.write(data)


def get_images():
    name = 1
    for i in range(1000):
        print(i)
        data = get_page()
        save_image(data, name)
        name += 1




def main():
    get_images()





if __name__ == '__main__':
    main()